/****************************************************************************
	This file is part of Basqet.

	Basqet is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Basqet is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
    along with Basqet.  If not, see <http://www.gnu.org/licenses/>.

****************************************************************************/

#include "removerecursiveworker.h"

#include <QFileInfo>
#include <QDir>

#include <QtDebug>

RemoveRecursiveWorker::RemoveRecursiveWorker()
{
}


void RemoveRecursiveWorker::removeRecursive(QFileInfo base)
{
	// qDebug() << "  ---removing " << base.filePath();
	if (base.isDir())
	{
		QDir currentDir(base.filePath());
		QFileInfoList content = currentDir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Files);

		foreach(QFileInfo entry, content)
		{
			if (entry.isDir())
			{
				removeRecursive(entry);
			}
			else if (entry.isFile())
			{
//				qDebug() << "Remove file:" << entry.filePath();
				currentDir.remove(entry.filePath());
			}
			else
			{
				qDebug() << "Cannot remove, not file or directory:" << entry.filePath();
			}
		}

		// qDebug() << "rmdir " << base.filePath();
		currentDir.rmdir(base.filePath());

	}

}

